<?php /*
	*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
	{
				
				$title=mysql_real_escape_string($_REQUEST['title']);
				$taxtcountry = mysql_real_escape_string($_REQUEST['question']);
				$taxtisocode2 = mysql_real_escape_string($_REQUEST['answer']);
				
				$insert = "INSERT INTO `tblfaq`
				(`vartitle`,`varquestion` ,`varanswer`)
				VALUES ('$title','$taxtcountry', '$taxtisocode2')";
				
				$sql=$obj_db->insert($insert);
				
				header("location:faq.php?msg=add");
				die();
	}	
		

// UPDATE the record
$txtcountry1 = "";
$txtisocode21 = "";
$p_title="";
$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  $_REQUEST['intid'];
		$sql = "select * from tblfaq where intid ='$screen_id'";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				$p_title = stripslashes($row['vartitle']);
				$txtcountry1 = stripslashes($row['varquestion']);	   
		   		$txtisocode21 = stripslashes($row['varanswer']);
				$action=2;
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
				
				$title=mysql_real_escape_string($_REQUEST['title']);
				$taxtcountry = mysql_real_escape_string($_REQUEST['question']);
				$taxtisocode2 = mysql_real_escape_string($_REQUEST['answer']);
			
			$sql_upd ="UPDATE tblfaq SET
						`vartitle`=  '$title',
						`varquestion` = '$taxtcountry',
						`varanswer` = '$taxtisocode2'						 
						where intid ='$screen_id'";
						 
		//echo $sql_upd;
			//die();
			
			$result = $obj_db->edit($sql_upd);
			$action=1;
			
			header("location:faq.php?msg=edit");
			die();
		}
	}

}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  $_REQUEST['intid'];
		$sql= "DELETE FROM `tblfaq` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		
		header("location:faq.php?msg=del");
		die();
	}
}


?>
<script language="javascript">
function check()
{
	var cond=true;
	if(document.faq.title.value.length==0)
	{
		alert("Please Enter Title.");
		if(cond==true)
		{
			document.faq.title.focus();
		}
		cond=false;
		return false;
	}	
	if(document.faq.question.value.length==0)
	{
		alert("Please Enter Question.");
		if(cond==true)
		{
			document.faq.question.focus();
		}
		cond=false;
		return false;
	}	
	if(document.faq.answer.value.length==0)
	{
		alert("Please Enter Answer.");
		if(cond==true)
		{
			document.faq.answer.focus();
		}
		cond=false;
		return false;
	}
}
</script>
<?php include("inc/header.php");?>
<body>

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%"><?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addfaq' || trim($_REQUEST['script'])=='editfaq')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="faq">
	
      <table width="60%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>
            <?php if($_REQUEST['script']=='addfaq'){echo "Add New FAQ...";}
	if($_REQUEST['script']=='editfaq'){echo "Edit FAQ...";}?>
          </strong></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">(* All fields are Required)</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left" class="sltimg">*Title</td>
          <td>:</td>
          <td align="left"><input name="title" type="text" id="title" value="<?php echo $p_title;?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="30%" align="left" class="sltimg">*Question </td>
          <td width="3%">:</td>
          <td width="56%" align="left"><label>
            <input name="question" type="text" id="question" value="<?php echo $txtcountry1;?>" />
          </label></td>
          <td width="9%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left" class="sltimg">*Answer </td>
          <td>:</td>
          <td align="left"><textarea name="answer" id="answer"><?php echo $txtisocode21;?></textarea></td>
          <td>&nbsp;</td>
        </tr>

        <tr>
          <td colspan="5" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();"/></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table>  </form>
    <?php
	}
}
else
{
?>
<br />
		<br />
		<table width="85%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr class="bg1">
            <td colspan="4"align="left"><strong >FAQ   List... </strong>&nbsp;&nbsp;<a href="currency.php?script=addcurrency" class="aa"></a><a href="currency.php?script=addcurrency" class="aa"></a></td>
            <td width="10%" align="center"><a href="faq.php?script=addfaq" class="aa">[NEW]</a></td>
          </tr>
          <tr align="center">
           <?php 
	   $rows="";
	 if(isset($_REQUEST['page']) && ($_REQUEST['page'])!="")
	 {
	 	$rows=$_REQUEST['page'];
	 
	  }	
	  ?><form name="form1" action="" method="post">
              <td colspan="5" align="left">
			  
			  Row per Page:
                <select name="page" onChange="document.form1.submit();">
                  <option value="0"<?php if($rows=='0'){echo "selected";}else{echo "";}?>>All</option>
                  <option value="5"<?php if($rows=='5'){echo "selected";}else{echo "";}?>>5 Per Page</option>
                  <option value="10"<?php if($rows=='10'){echo "selected";}else{echo "";}?>>10 Per Page</option>
                  <option value="15"<?php if($rows=='15'){echo "selected";}else{echo "";}?>>15 Per Page</option>
                </select>
				
			 </td>
				</form>
          </tr>
          <tr align="center" class="tblbg3">
		  <td width="14%" height="20" class="tblbg3">Title</td>
            <td width="26%" class="tblbg3">Question</td>
            <td width="42%" class="tblbg3">Answer</td>
			<td width="8%" class="tblbg3">Edit</td>
            <td>Delete</td>
          </tr>
          <?php
	  
	  /**************************************
				PAGING CODE START
		**************************************/
			if(isset($_REQUEST['page']) && ($_REQUEST['page'])!=0)
			{
				$rows=$_REQUEST['page'];
				$rowperpage=$rows;
			}else{$rowperpage=$rows=10000;}
			$tablename="tblfaq";
			$per_page_keywords= "";
			$per_page_sorts="";
			include("system/paging.inc.php");

		/**************************************
				PAGING CODE ENDING
		**************************************/
	  
	  
		?>
          <?php
   		$sql="select * from tblfaq Limit ".($page_no*$row_per_page).",".$row_per_page;
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			//$imagepath = "../images/manuf/";
			//$limit=$result[$i]['varimagepath'];
			//$imagename = $imagepath.$limit;
			?>
          <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
		  	<td align="center"><?php echo stripslashes($result[$i]['vartitle']);?></td>
            <td align="center"><?php echo stripslashes($result[$i]['varquestion']);?></td>
            <td align="center"><?php echo stripslashes($result[$i]['varanswer']);?></td>
			
			<td align="center"><a class="link" Title="Click here to Edit" href="faq.php?script=editfaq&amp;a=2&amp;intid=<?php echo $result[$i]['intid']; ?>"><img src="images/edit.bmp" border="0"/></a></td>
            <td align="center"><a Title="Click here to Delete" href="faq.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
          </tr>
          <?php }}?>
          <tr>
            <td colspan="7" align="center" class="aa"><?php
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?></td>
          </tr>
        </table>
		<?php }?>
   	</td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>


